<template>
  <a-modal
    title="通过"
    :width="640"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
  >
    <div>
      <a-row>
        <a-col :span="12">
          <label >拒绝类型：</label>
          <a-select :value="refuseType" style="max-width: 80%;width:200px" @change="selectChange">
            <a-select-option :value="re.id" v-for="(re, index) in refuseList" :key="index">{{ re.text }}</a-select-option>
          </a-select>
        </a-col>
        <a-col :span="12">
          <label >短信通知：</label>
          <a-radio-group v-model="radio" buttonStyle="solid">
            <a-radio-button :value="true">是</a-radio-button>
            <a-radio-button :value="false">否</a-radio-button>
          </a-radio-group>
        </a-col>
      </a-row>
      <p style="margin-top:50px">拒绝原因：</p>
      <a-textarea v-model="cause" placeholder="拒绝原因内容" :rows="4" />
    </div>
    <template slot="footer">
      <a-button key="cancel" @click="handleCancel">取消</a-button>
      <a-button key="forward" :loading="confirmLoading" type="primary" @click="handleNext()">确定</a-button>
    </template>
  </a-modal>
</template>

<script>
import { mapActions } from 'vuex'
export default {
  name: 'NotModel',
  components: {
  },
  data () {
    return {
      refuseType: '',
      refuseList: [],
      cause: '',
      id: '',
      radio: true,
      visible: false,
      confirmLoading: false
    }
  },
  methods: {
    ...mapActions(['AuditPass', 'SensitiveList']),
    not (record) {
      this.id = record.id
      this.visible = true
      this.SensitiveList({
        keyword: '',
        page: 1,
        pageSize: 100000
      })
        .then((res) => {
          if (res.status === 200 || res.status === '200') {
            if (res.data.list && res.data.list.length !== 0) {
              this.refuseList = res.data.list
            }
          } else {
            this.requestFailed(res)
          }
        })
        .catch(err => this.requestFailed(err))
    },
    selectChange (val) {
      for (var i in this.refuseList) {
        if (this.refuseList[i].id === val) {
          this.refuseType = this.refuseList[i].text
        }
      }
    },
    handleCancel () {
      this.visible = false
    },
    handleNext () { // 通过
      this.confirmLoading = true
      var data = {
        id: this.id,
        status: 2,
        notification: this.radio,
        rejectType: this.refuseType,
        rejectReason: this.cause
      }
      this.AuditPass(data)
        .then((res) => this.passSuccess(res))
        .catch(err => this.requestFailed(err))
    },
    passSuccess (res) {
      if (res.status === 200 || res.status === '200') {
        this.$notification['success']({
          message: '成功',
          description: '已成功拒绝',
          duration: 4
        })
        setTimeout(() => {
          this.visible = false
          this.$emit('ok', res)
          this.confirmLoading = false
        }, 1000)
      } else {
        this.requestFailed(res)
      }
    },
    requestFailed (err) {
      this.$notification['error']({
        message: '错误',
        description: err.message || '请求出现错误，请稍后再试',
        duration: 4
      })
      setTimeout(() => {
        this.confirmLoading = false
      }, 1000)
    }
  }
}
</script>
<style lang="less" scoped>
</style>
